package com.wed.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.Spring;

public class DBConnect {
	  private Connection connection;

	    public Connection getConnection() {
	        return connection;
	    }
	    public void open()
	    {
	        try
	        {
	            DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
	             String connectionString = "jdbc:mysql://localhost:3306/quanlinhasach";
	            Properties pros = new Properties();
	            pros.setProperty("characterEncoding", "utf8");
	            pros.setProperty("user", "root");
	            pros.setProperty("password", "1234");
	            this.connection = DriverManager.getConnection(connectionString, pros);
	        }
	        catch(SQLException ex)
	        {
	            System.out.println(ex.getMessage());
	        }
	    }
	    public void close()
	    {
	        try
	        {
	            this.connection.close();
	        }
	        catch(SQLException ex)
	        {
	            Logger.getLogger(DBConnect.class.getName()).log(Level.SEVERE, null, ex) ;
	        }
	    }
	    public ResultSet excuteQuery(String sql)
	    {
	        ResultSet rs=null;
	        try
	        {
	            Statement sm=this.connection.createStatement();
	            rs=sm.executeQuery(sql);
	        }
	        catch(SQLException ex)
	        {
	            System.out.println(ex.getMessage());
	        }
	        return rs;
	    }
	  
	public static void main(String[] args) throws SQLException {
		System.out.print("ds");
	}
}
